const UserApi = require("../api/user.js");
const commonUtil = require("../utils/common.js");

Component({
  properties: {
    _globalData: {type: Object, value: {}},
    modalContent: {type: Object, value: {title: null, content: null}},
    reload: {type: Boolean, value: false}
  },
  options: {
    addGlobalClass: true
  },
  observers: {
    '_globalData': function(){
      console.log(this.properties._globalData);
      this.setData({globalData: this.properties._globalData})
    }
  },
  data: {
    globalData: {
      userService: null
    },
    userInfo: wx.getStorageSync('userInfo'),
  },
  methods: {
    toLogin(){
      wx.removeStorageSync('userService')
      wx.removeStorageSync('userInfo')
      wx.removeStorageSync('tokenExpire')
      wx.removeStorageSync('token')
      setTimeout(()=>{
        wx.redirectTo({
          url: '/packageA/pages/login/index?redirect_uri=/packageA/pages/quotation/index&redirect_uri_type=link',
        })
      }, 200)
    },
    toApply(){
      let _this = this;
      UserApi.applyMemberServiceOrder().then(res=>{
        if (res.retCode == '000000' && res.errCode == '000000') {
          wx.showToast({icon: 'success', title: "申请数据试用成功"})
          commonUtil.getUserServiceState();
          setTimeout(()=>{
            let userService = wx.getStorageSync('userService');
            _this.setData({
              ['globalData.userService']: userService
            })
          }, 200)
        } else {
          wx.showToast({icon: 'error', title: res.errMsg})
        }
      })
    },
    toActived() {
      let userInfo = wx.getStorageSync('userInfo');
      wx.setStorageSync('resetInfo', {'action': 'set', phoneNumber: userInfo.phoneNumber})
      wx.redirectTo({
        url: '/packageA/pages/forgetPsw/index?redirect_uri=/packageA/pages/quotation/index&redirect_uri_type=link',
      })
    },
    getCustomerService() {
      this.triggerEvent('customerService');
    },
    renewalContract(){
      wx.navigateTo({
        url: '/packageA/pages/renewalServices/index',
      })
    },
  }
})